<?php
class Homepage extends MY_Controller 
{
	var $curl = 'homepage';
	var $language;
	var $submenu = "_menu";	
	
	function __construct()
	{
		
		parent::__construct();

		$this->load->model(array('/public/homepage_model', '/public/referral_model', '/public/book_model', '/public/section_model'));
				
		$this->data['Title'] = '';		
		$this->data['curl'] = $this->curl;	
		$this->language = parent::getLang();
	}
	
	function index($user_role = null)
	{	
		$this->referral_model->search_home_page();
		$this->referral_model->number_users();
		$this->book_model->search_books_hom();
		
		$this->data['sections'] = $this->section_model->getSectionList();
        $this->renderLayout();
	}

	function language()
	{
		$lang = $this->input->post('lang');
		if ($lang)
		{
			$this->language = $lang;
			redirect($lang . '/' . $this->curl . '/index');	
		}		
	}
	
    function welcome()
    {       
        $this->renderLayout();
    }
	
	function search() {
		$params = array('query' => '', 'for_name' => false, 'lang_only' => false);	
		$params['query'] = $this->input->post('query');
		$params['for_name'] = (isset($_POST['search_name']) && $_POST['search_name'] == true) ? true : false;
		$params['lang_only'] = (isset($_POST['search_lang']) && $_POST['search_lang'] == true) ? true : false;
		
		$result = $this->book_model->searchBook($params);
		exit;
	}
}
?>